package me.tuyou.aop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author tuyou_cd
 * @Date 2020/5/28 14:02
 */
@Component
@Aspect
public class AopAspect {

    //包扫描方式
//    @Pointcut("execution(* me.tuyou.aop.bean.*.*(..))")
    //注解扫描方式
    @Pointcut("@annotation(me.tuyou.aop.annotation.MyLog)")
    public void test() {
        //方法体写了也不会执行
        System.out.println("...");
    }

    @Before("test()")
    public void before(JoinPoint joinPoint) {
        System.out.println("before " + joinPoint.getSignature().getName());
    }

    @After("test()")
    public void after(JoinPoint joinPoint) {
        System.out.println("after " + joinPoint.getSignature().getName());
    }

//    @Around("test()")
//    public Object round(ProceedingJoinPoint joinPoint) {
//        System.out.println("round before");
//        try {
//            return joinPoint.proceed();
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//        } finally {
//            System.out.println("round after");
//        }
//        return null;
//    }
}
